﻿<%@ WebHandler Language="C#" Class="userMgr" %>

using System;
using System.Web;
using System.Data;
using System.Text;
using System.IO;
using Chenxin.Lib.Utility;
using System.Collections.Generic;

//****************************************************************
//   臣信二手房
//   Copyright (c) 2010 Chenxin.                        
//****************************************************************
//****************************************************************      
//作成者       :  he.jifeng   
//创建日期     :  2010-03-04                 
//確認者       :  確認者          
//功能概要　   :  人事查询
//****************************************************************
public class userMgr : AjaxHandlerBase
{

    public userMgr()
    {
        //添加员工
        htTypePermit.Add("add", Constants.Permit_Hr_AddUser);
        //编辑员工
        htTypePermit.Add("edit", Constants.Permit_Hr_EditUser);
        //添加虚账号
        htTypePermit.Add("virtual", Constants.Permit_Hr_AddVirtualUser);
        //人事变动
        htTypePermit.Add("change", Constants.Permit_Hr_AddUserChange);
        //导出Excel
        htTypePermit.Add("exportdata", Constants.Permit_Hr_ExportUserList);
        //添加职权
        htTypePermit.Add("addterms", Constants.Permit_Hr_AddTerms);
        //删除职权
        htTypePermit.Add("delterms", Constants.Permit_Hr_DelTerms);
        //激活账号
        htTypePermit.Add("activate", Constants.Permit_Hr_ActivateUser);
        //冻结账号
        htTypePermit.Add("freeze", Constants.Permit_Hr_FreezeUser);
        //密码重置
        htTypePermit.Add("resetpwd", Constants.Permit_PasswordReset);
        //详细模式
        htTypePermit.Add("detailssearch", Constants.Permit_ViewHrUserInfoDetail);  
    }

    private Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
    
    //*******************************************
    //功能概要       ：重写的请求处理方法
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：父类中隐藏了IHttpHandler接口方法，本类中须对本方法进行重写
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-04 
    //*******************************************
    override public void RequestProcess(HttpContext context)
    {
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        
        //处理类型
        string strDealType  = context.Request.Params["op"];

        switch (strDealType.ToLower())
        {
            case "getcondition":    
                getCondition(context);
                break;
            case "search":      //查询人事基本信息
                searchUserInfo(context,"1");
                break;
            case "birthdaysearch":      //查询人事基本信息(生日模式)
                searchUserInfo(context,"2");
                break;
            case "detailssearch":      //查询人事基本信息（详细模式）
                searchUserInfo(context,"3");
                break;
            case "simplesearch":      //查询人事基本信息（简单模式）
                searchUserInfo(context,"1");
                break;
            case "add":         //添加员工
                addUserInfo(context);
                break;
            case "getbaseinfo": //得到员工数据
                getUserInfo(context);
                break;
            case "edit":        //编辑员工信息
                editUserInfo(context);
                break;
            case "pageshow":    //职权职务关系 or 人事职权 分页显示
                pageShow(context);
                break;
            case "change":      //人事变动
                UserChange_HR(context);
                break;
            case "addterms":    //添加人员职权
                AddTermsOperation(context);
                break;
            case "delterms":    //删除人员职权
                DelTermsOperation(context);
                break;
            case "virtual":     //添加虚账号
                AddVirtual(context);
                break;
            case "getallcompany":   //得到所有公司数据
                getAllCompany(context);
                break;
            case "getterms":        //根据条件得到相应的职务
                getTerms(context);
                break;
            case "activate":        //激活账号
                ActivateUser(context);
                break;
            case "freeze":          //冻结账号
                FreezeUser(context);
                break;
            case "checkidno":         //验证身份证号
                CheckID(context);
                break;
            case "getdelrolebycompany":     //得到默认角色
                GetDefRole(context);
                break;
            case "exportdata":      //导出全部
                ExportData(context);
                break;
        }
    }

    private void ExportData(HttpContext context)
    {
        //参数列表
        System.Collections.Hashtable htParams = new System.Collections.Hashtable();
        //当前参数
        string strParam;

        //条件
        strParam = context.Request.Params["Condition"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("Condition", strParam);
        }
        //生日
        strParam = context.Request.Params["divBirthday"];
        if (strParam != null & strParam != "" & strParam != "0")
        {
            htParams.Add("divBirthday", strParam);
        }
        //状态
        strParam = context.Request.Params["divStatus"];
        //全部或者为空的场合
        if (strParam != null & strParam != "" & strParam != "0")
        {
            htParams.Add("Status", strParam);
        }
        //到职时间（开始）
        strParam = context.Request.Params["ComeDateFrom"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("ComeDateFrom", strParam);
        }
        //到职时间（结束）
        strParam = context.Request.Params["ComeDateTo"];
        if (strParam != null & strParam != null & strParam != "")
        {
            htParams.Add("ComeDateTo", strParam);
        }
        //合同开始时间（开始）
        strParam = context.Request.Params["ContractDateFrom"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("ContractDateFrom", strParam);
        }
        //合同开始时间（结束）
        strParam = context.Request.Params["ContractDateTo"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("ContractDateTo", strParam);
        }
        //离职时间（开始）
        strParam = context.Request.Params["LeaveDateFrom"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("LeaveDateFrom", strParam);
        }
        //离职时间（结束）
        strParam = context.Request.Params["LeaveDateTo"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("LeaveDateTo", strParam);
        }
        //身份证号
        strParam = context.Request.Params["IDNo"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("IDNo", strParam);
        }
        //角色
        strParam = context.Request.Params["divRole"];
        if (strParam != null & strParam != "" & strParam != "0")
        {
            htParams.Add("RoleId", strParam);
        }
        //职务
        strParam = context.Request.Params["Position"];
        if (strParam != null & strParam != "" & strParam != "0")
        {
            htParams.Add("Position", strParam);
        }
        //虚账号
        strParam = context.Request.Params["divIsVirtual"];
        if (strParam != null)
        {
            htParams.Add("IsVirtual", strParam);
        }
        //公积金账号
        strParam = context.Request.Params["FundCode"];
        if (strParam != null)
        {
            htParams.Add("FundCode", strParam);
        }
        //手机号码
        strParam = context.Request.Params["Mobile"];
        if (strParam != null)
        {
            htParams.Add("Mobile", strParam);
        }
        //家庭电话
        strParam = context.Request.Params["HomeTel"];
        if (strParam != null)
        {
            htParams.Add("HomeTel", strParam);
        }
        //办公电话
        strParam = context.Request.Params["OfficeTel"];
        if (strParam != null)
        {
            htParams.Add("OfficeTel", strParam);
        }
        //快捷方式
        strParam = context.Request.Params["quicktype"];
        if (strParam != null)
        {
            htParams.Add("quicktype", strParam);
        }
        //排序
        strParam = context.Request.Params["sort"];
        if (!string.IsNullOrEmpty(strParam))
        {
            htParams.Add("sort", strParam);
        }

        strParam = context.Request.Params["ConditionType"];
        if (strParam != null & strParam != "")
        {
            string strConditionId = context.Request.Params["ConditionId"];
            if (strParam == "DepartInfo")
            {
                htParams.Add("DepartId", strConditionId);
            }
            else
            {
                htParams.Add("UserId", strConditionId);
            }
        }
        strParam = context.Request.Params["keyword"];
        if (!string.IsNullOrEmpty(strParam))
        {
            htParams.Add("keyword", strParam);
        }

        strParam = context.Request.Params["showtype"];
        htParams.Add("show", strParam);
        
        
        strParam = (string.IsNullOrEmpty(context.Request["cityid"])) ? Guid.Empty.ToString() : context.Request["cityid"];
        htParams.Add("cityid_s", strParam);
        strParam = (string.IsNullOrEmpty(context.Request["companyid"])) ? Guid.Empty.ToString() : context.Request["companyid"];
        if (context.Request["cityid"] == Guid.Empty.ToString() || string.IsNullOrEmpty(context.Request["cityid"]))
            htParams.Add("companyid_s", CurrentUserInfo.CompanyId.ToString());
        else
            htParams.Add("companyid_s", strParam);
        strParam = (string.IsNullOrEmpty(context.Request["areaid"])) ? Guid.Empty.ToString() : context.Request["areaId"];
        htParams.Add("areaid_s", strParam);
        strParam = (string.IsNullOrEmpty(context.Request["departid"])) ? Guid.Empty.ToString() : context.Request["departid"];
        htParams.Add("departid_s", strParam);
        strParam = (string.IsNullOrEmpty(context.Request["userid"])) ? Guid.Empty.ToString() : context.Request["userid"];
        htParams.Add("userid_s", strParam);

        //权限判断
        //查看所有权限
        if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewAllHrUserInfo))
        {
            htParams.Add("Permit", Constants.Permit_ViewAllHrUserInfo);
        }
        //查看城市权限
        else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewCityHrUserInfo))
        {
            htParams.Add("Permit", Constants.Permit_ViewCityHrUserInfo);
            htParams.Add("CurCityId", CurrentUserInfo.CityId);
        }
        //查看公司权限
        else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewCompanyHrUserInfo))
        {
            htParams.Add("Permit", Constants.Permit_ViewCompanyHrUserInfo);
            htParams.Add("CurCompanyId", CurrentUserInfo.CompanyId);
        }
        //查看部门权限
        else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewDepartHrUserInfo))
        {
            htParams.Add("Permit", Constants.Permit_ViewDepartHrUserInfo);
            htParams.Add("CurUserId", CurrentUserInfo.UserId);
        }
        //查看自己权限    
        else
        {
            htParams.Add("CurUserId", CurrentUserInfo.UserId);
        }

        try
        {
            Chenxin.Lib.Passport.BLL.Hr_UserInfo blluserinfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();
            string strHtml = blluserinfo.ExportData(htParams);

            ExportByServce(context, strHtml); 
        }
        catch (Exception ex)
        {
            context.Response.Write(string.Format("{{success:'0',msg:'意外错误：{0}',data:''}}", ex.Message));
        }
    }
    
    //得到默认角色
    private void GetDefRole(HttpContext context)
    {
        try
        {
            string companyid = context.Request.Params["companyid"];
            string strSql = string.Format("CompanyId='{0}' and defrole=1", companyid);

            List<Chenxin.Lib.Hr.Entity.Base_Permit_RoleDefine> list = Chenxin.Lib.Hr.DAL.Base_Permit_RoleDefine.GetListArray(strSql);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (list.Count > 0)
            {
                foreach (Chenxin.Lib.Hr.Entity.Base_Permit_RoleDefine r in list)
                {
                    sb.AppendFormat("{{txt:'{0}',val:'{1}'}},", r.RoleName, r.RoleId);
                }
                sb.Remove(sb.Length - 1, 1);
            }
            context.Response.Write(string.Format("{{success:'1',msg:'',data:{{items:[{0}]}}}}", sb.ToString()));
        }
        catch (Exception ex)
        {
            context.Response.Write(string.Format("{{success:'0',msg:'意外错误：{0}',data:''}}", ex.Message));
        }
    }
    
    //验证证件号是否重复
    private void CheckID(HttpContext context)
    {
        try
        {
            string idno = "";
            if (!string.IsNullOrEmpty(context.Request.Params["IDNo"]))
                idno = context.Request.Params["IDNo"];
            if (!string.IsNullOrEmpty(context.Request.Params["txtIDNO"]))
                idno = context.Request.Params["txtIDNO"];
            string strSql = string.Format("IDNo='{0}'", idno);
            if(Chenxin.Lib.Passport.DAL.Hr_UserInfo.getTotalCnt(strSql)>0)
                context.Response.Write(retExecResult(Constants.ExecResult.Succ, "存在相同证件号！", ""));  
            else
                context.Response.Write(retExecResult(Constants.ExecResult.Succ, " ", ""));  
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }
    
    //冻结账号
    private void FreezeUser(HttpContext context)
    {
        try
        {
            string userid = context.Request.Params["modelid"];
            Chenxin.Lib.Passport.BLL.Hr_UserInfo blluserinfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();
            Chenxin.Lib.Passport.Entity.Hr_UserInfo model = blluserinfo.GetEntityById(new Guid(userid));
            if (!model.Validate)
            {
                context.Response.Write(retExecResult(Constants.ExecResult.Error, "该账号已冻结，操作失败！", ""));
            }
            else
            {
                string strSql = string.Format("update Hr_UserInfo set Validate=0,UpdateTime=getdate() where UserId='{0}'", userid);
                bool flag = Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.ExecuteSQL(strSql);

                //用户信息键
                string strGKeyUser = string.Format(Chenxin.Lib.Cache.CacheDataType.USER, userid);
                string strGUser = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_USER, userid);

                //删除部门下用户的缓存
                cs.Delete(strGKeyUser);
                cs.Delete(strGUser);

                string strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, model.DepartId + ".0");
                cs.Delete(strKDepUsers);
                strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, model.DepartId + ".1");
                cs.Delete(strKDepUsers);

                if (flag)
                {
                    context.Response.Write(retExecResult(Constants.ExecResult.Succ, "冻结成功！", ""));
                    
                    Chenxin.Lib.Passport.Entity.Hr_UserInfo entUserInfo = Chenxin.Lib.Passport.DAL.Hr_UserInfo.GetEntityById(userid);
                    AddLog("" + CurrentUserInfo.UserName + "冻结账号:员工姓名[" + entUserInfo.UserName + "(" + entUserInfo.UserCode + ")]",
                    OperationType.OperationTypeComboList()["OprType_UserFreeze"].ToString());
                }
                else
                    context.Response.Write(retExecResult(Constants.ExecResult.Error, "传递参数错误！", ""));
            }
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }
    
    
    //激活账号
    private void ActivateUser(HttpContext context)
    {
        try
        {
            string userid = context.Request.Params["modelid"];
            Chenxin.Lib.Passport.BLL.Hr_UserInfo blluserinfo  = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();
            Chenxin.Lib.Passport.Entity.Hr_UserInfo model = blluserinfo.GetEntityById(new Guid(userid));
            if (model.Validate)
            {
                context.Response.Write(retExecResult(Constants.ExecResult.Error, "该员工已激活，操作失败！", ""));
            }
            else
            {
                string strSql = string.Format("update Hr_UserInfo set Validate=1,NeedChgPass=1,UpdateTime=getdate() where UserId='{0}'", userid);
                bool flag = Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.ExecuteSQL(strSql);

                //用户信息键
                string strGKeyUser = string.Format(Chenxin.Lib.Cache.CacheDataType.USER, userid);
                string strGUser = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_USER, userid);

                //删除部门下用户的缓存
                cs.Delete(strGKeyUser);
                cs.Delete(strGUser);

                string strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, model.DepartId + ".0");
                cs.Delete(strKDepUsers);
                strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, model.DepartId + ".1");
                cs.Delete(strKDepUsers);

                if (flag)
                {
                    context.Response.Write(retExecResult(Constants.ExecResult.Succ, "激活成功！", ""));
                    Chenxin.Lib.Passport.Entity.Hr_UserInfo entUserInfo = Chenxin.Lib.Passport.DAL.Hr_UserInfo.GetEntityById(userid);
                    AddLog("" + CurrentUserInfo.UserName + "激活账号:员工姓名[" + entUserInfo.UserName + "(" + entUserInfo.UserCode + ")]",
                    OperationType.OperationTypeComboList()["OprType_UserActivate"].ToString());
                }
                else
                    context.Response.Write(retExecResult(Constants.ExecResult.Error, "传递参数错误！", ""));
            }          
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }
    
    //根据条件得到相应的职务
    private void getTerms(HttpContext context)
    {
        string companyid = context.Request.Params["companyid"];
        string str = "";
        
        if (companyid == "0")
            context.Response.Write("");
        else {
            string strSql = string.Format("ItemKey= 'System.Position' and ItemValue not in (select OfficeName from Chenxin_Main.dbo.HR_Rel_Office where CompanyID='{0}') and CompanyID='{1}'",companyid,companyid);
            DataSet ds = Chenxin.Lib.House.DAL.DataDictionary.GetList(strSql,"");
            if (ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        str += string.Format("{{ txt: '{0}', val: '{1}' }},", dr["ItemValue"].ToString(), dr["ItemValue"].ToString());
                    }
                    str = str.Substring(0, str.Length - 1);
                }
                else
                    str = "";
            }
            context.Response.Write(str);
        }
    }
    
    
    
    //得到所有公司
    private void getAllCompany(HttpContext context)
    {
        List<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo> list = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetListArray("DepartProperty=200");
        
        //生成JSON字符串
        System.Text.StringBuilder str = new System.Text.StringBuilder();

        foreach (Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo item in list)
        {
            str.Append(", { txt: '" + item.DepartName.Trim() + "', val: '" + item.DepartId + "' }");
        }
        context.Response.Write(retExecResult(Constants.ExecResult.Succ, "", str.ToString()));
    }
    
    
    //*******************************************
    //功能概要       ：添加虚账号
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：添加虚账号
    //作成者         ：薛彦 
    //作成日         ：2010-04-07
    //*******************************************
    private void AddVirtual(HttpContext context)
    {
        try
        {

            //用户基本信息业务类
            Chenxin.Lib.Passport.BLL.Hr_UserInfo bllUserInfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();
            //用户基本信息实体类
            Chenxin.Lib.Passport.Entity.Hr_UserInfo entUserInfo =
            (Chenxin.Lib.Passport.Entity.Hr_UserInfo)Chenxin.Lib.Utility.JsonHelp.Convert2Entity(context.Request["model"], typeof(Chenxin.Lib.Passport.Entity.Hr_UserInfo));
           
            entUserInfo.ComeDate = DateTime.Now;

            //是否冻结
            entUserInfo.Validate = false;

            //密码（暂时固定）
            entUserInfo.Password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("111", "MD5");
            //姓名品应首字母
            entUserInfo.Initial = Chenxin.Lib.Utility.InitialHelper.GetChineseSpell(entUserInfo.UserName).Substring(0, 1);
            //是否虚拟账号
            entUserInfo.IsVirtual = true;
            //员工编号
            string usercode = Chenxin.Lib.Passport.BLL.Hr_UserInfo.GetUserCode(Guid.Empty, "CXSH_X");
            entUserInfo.UserCode = usercode;
            //流水号
            entUserInfo.SerialCode = entUserInfo.UserCode.Replace("CXSH_X", "");
            entUserInfo.Status = 1;
            entUserInfo.Sex = 0;
            entUserInfo.UserId = Guid.NewGuid();
            entUserInfo.UserType = 0;
            entUserInfo.Validate = false;
            
            bllUserInfo.Add(entUserInfo);

            //添加操作日志
            
            //string strSql = string.Format("insert into Hr_UserLogs values(newid(),'{0}','{1}','{2}','{3}','{4}','添加虚拟账号','{2}-添加虚拟账号:{5}',getdate())", entUserInfo.UserId.ToString(), CurrentUserInfo.UserId.ToString(), CurrentUserInfo.UserName, CurrentUserInfo.DepartId.ToString(), CurrentUserInfo.DepartName, entUserInfo.UserName + "(" + entUserInfo.UserCode + ")");
            //Chenxin.Lib.Passport.DAL.Hr_UserInfo.ExecuteSQL(strSql);
            AddLog("" + CurrentUserInfo.UserName + "添加虚账号:员工姓名[" + entUserInfo.UserName + "("+entUserInfo.UserCode+")]",
                    OperationType.OperationTypeComboList()["OprType_UserVirtualAdd"].ToString());

            context.Response.Write(retExecResult(Constants.ExecResult.Succ, "添加成功", ""));
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }        
    }
    
    /// <summary>
    /// 员工职权添加
    /// </summary>
    /// <param name="context"></param>
    private void AddTermsOperation(HttpContext context)
    {
        try
        {
            //员工职权实体类
            Chenxin.Lib.Hr.Entity.Hr_Struct_UserDepartRelation clhehsudr =
            (Chenxin.Lib.Hr.Entity.Hr_Struct_UserDepartRelation)Chenxin.Lib.Utility.JsonHelp.Convert2Entity(context.Request["model"], typeof(Chenxin.Lib.Hr.Entity.Hr_Struct_UserDepartRelation));
            
            //用户ID
            string userid = clhehsudr.UserId.ToString();
            //用户姓名
            string username = clhehsudr.UserName;
            //部门ID
            string depid = clhehsudr.DepartId.ToString();
            //部门名称
            string depname = clhehsudr.DepartName;
            //职权类型
            string roletype = clhehsudr.RoleType.ToString();
            //开始时间
            DateTime comedate = clhehsudr.ComeDate;

            string Sql = string.Format("select count(*) from Hr_Struct_UserDepartRelation where UserId='{0}' and DepartId='{1}';", userid, depid);
            if (Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.SearchSQL(Sql))
            {
                context.Response.Write(retExecResult(Constants.ExecResult.Error, "已添加过该部门员工职权，添加失败！", ""));
            } 
            else
            {
                string strSql = string.Format("insert into Hr_Struct_UserDepartRelation(RecordId,DepartId,DepartName,UserId,UserName,IsBelong,ComeDate,RoleType,Addtime) values(newid(),'{0}','{1}','{2}','{3}','0','{4}','{5}',getdate());", depid, depname, userid, username, comedate, roletype);

                bool flag = Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.ExecuteSQL(strSql);

                
                //strSql = string.Format("insert into Hr_UserLogs values(newid(),'{0}','{1}','{2}','{3}','{4}','添加员工职权','{2}-添加员工职权:{5}',getdate())", userid, CurrentUserInfo.UserId.ToString(), CurrentUserInfo.UserName, CurrentUserInfo.DepartId.ToString(), CurrentUserInfo.DepartName, username);
                //Chenxin.Lib.Passport.DAL.Hr_UserInfo.ExecuteSQL(strSql);
                //添加操作日志
                AddLog("" + CurrentUserInfo.UserName + "添加职权:员工姓名[" + username + "]",
                        OperationType.OperationTypeComboList()["OprType_UserTermsAdd"].ToString());

                if (flag)
                    context.Response.Write(retExecResult(Constants.ExecResult.Succ, "添加成功！", ""));
                else
                    context.Response.Write(retExecResult(Constants.ExecResult.Error, "结束时间早于开始时间，请重新输入结束时间！", ""));
            }

        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }

    /// <summary>
    /// 员工职权删除
    /// </summary>
    /// <param name="context"></param>
    private void DelTermsOperation(HttpContext context)
    {
        try
        {   
            //记录ID
            string modelid = context.Request.Params["modelid"];
            //结束时间
            DateTime endtime = DateTime.Parse(context.Request.Params["endtime"].ToString());
            if (Chenxin.Lib.Passport.BLL.Hr_UserInfo.CheckTime(modelid, endtime, 2))
            {
                
                string strSql = "";
                strSql += string.Format("insert into Hr_Struct_UserDepartRelation_History select newid(),DepartId,DepartName,UserId,UserName,IsBelong,ComeDate,'{0}',RoleType,getdate() from Hr_Struct_UserDepartRelation where RecordId='{1}';", endtime, modelid);
                strSql += string.Format("delete from Hr_Struct_UserDepartRelation where RecordId='{0}';", modelid);

                bool flag = Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.ExecuteSQL(strSql);

                //添加操作日志
                //strSql = string.Format("insert into Hr_UserLogs values(newid(),'{0}','{1}','{2}','{3}','{4}','删除员工职权','{2}-删除员工职权:',getdate())", modelid, CurrentUserInfo.UserId.ToString(), CurrentUserInfo.UserName, CurrentUserInfo.DepartId.ToString(), CurrentUserInfo.DepartName);
                //Chenxin.Lib.Passport.DAL.Hr_UserInfo.ExecuteSQL(strSql);
                AddLog("" + CurrentUserInfo.UserName + "删除职权",
                        OperationType.OperationTypeComboList()["OprType_UserTermsDel"].ToString());
                
                if (flag)       
                    context.Response.Write(retExecResult(Constants.ExecResult.Succ, "删除成功！", ""));
                else
                    context.Response.Write(retExecResult(Constants.ExecResult.Error, "删除失败！", ""));
            }
            else
            {
                context.Response.Write(retExecResult(Constants.ExecResult.Error, "结束时间早于开始时间，请重新输入结束时间！", ""));
            }

        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }    
    }

    //*******************************************
    //功能概要       ：员工人事变动
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：员工人事变动
    //作成者         ：薛彦 
    //作成日         ：2010-04-06
    //*******************************************
    private void UserChange_HR(HttpContext context)
    {
        try
        {
            //用户基本信息实体类
            Chenxin.Lib.Passport.Entity.Hr_ChangeUserHR clpehcyr =
            (Chenxin.Lib.Passport.Entity.Hr_ChangeUserHR)Chenxin.Lib.Utility.JsonHelp.Convert2Entity(context.Request["model"], typeof(Chenxin.Lib.Passport.Entity.Hr_ChangeUserHR));

            //用户ID
            string userid = clpehcyr.UserId.ToString();
            //部门ID(变动至)
            string depid = clpehcyr.DepartId.ToString();
            if (depid == "")
                depid = Guid.Empty.ToString();
            //部门名称（变动至）
            string depname = clpehcyr.DepartName;
            //变动类型
            string type = clpehcyr.TransType;
            //变动类型序号
            string typeid = clpehcyr.TransTypeId;
            //变动日期
            DateTime datetime = (DateTime)clpehcyr.TransTime;
            //变动职务
            string Position = "";
            if (!string.IsNullOrEmpty(clpehcyr.Position))
                Position = clpehcyr.Position;
            //变动职级
            string Level = "";
            if (!string.IsNullOrEmpty(clpehcyr.Level))
                Level = clpehcyr.Level;
            //变动理由
            string Reason = clpehcyr.TransReason;

            //操作类型
            int OperateType = 0;

            Chenxin.Lib.Passport.BLL.Hr_UserInfo bllUserInfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();

            //离职或调休
            if (typeid == "1" || typeid == "7")
                OperateType = 2;
            //else if (typeid == "4")
            //    OperateType = 3;
            else if (typeid == "2" || typeid == "3")
                OperateType = 4;
            else if (typeid == "8")
                OperateType = 1;
            else
                OperateType = 5;

            Chenxin.Lib.Passport.Entity.Hr_UserInfo olduserinfo = Chenxin.Lib.Passport.DAL.Hr_UserInfo.GetEntityById(userid);
            
            
            string setting="";
            if (OperateType == 1)
            {
                Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo depinfo = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetModel(new Guid(depid));
                olduserinfo.CityId = olduserinfo.BelongCityId = depinfo.CityId;
                olduserinfo.BelongCityName = olduserinfo.CityName = depinfo.City;
                olduserinfo.CompanyId = olduserinfo.BelongCompanyId = depinfo.CompanyId;
                olduserinfo.BelongCompanyName = olduserinfo.CompanyName = depinfo.CompanyName;
                olduserinfo.BelongDepart = olduserinfo.DepartName = depname;
                olduserinfo.DepartId = olduserinfo.BelongDepartId = new Guid(depid);
                olduserinfo.Validate = false;
                olduserinfo.ComeDate = datetime;
                olduserinfo.Password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("123456", "MD5");
                olduserinfo.Status = 1;
                olduserinfo.UpdateTime = DateTime.Now;

                Chenxin.Lib.Passport.DAL.Hr_UserInfo.Update(olduserinfo);
                
                setting = Chenxin.Lib.Passport.BLL.Hr_UserInfo.UserSetting(userid, 1, "", "", datetime, "", Guid.Empty, "", "", "");
            }
            else
            
            {
                if (!Chenxin.Lib.Passport.BLL.Hr_UserInfo.CheckTime(userid, datetime, 1))
                {
                    setting = Chenxin.Lib.Passport.BLL.Hr_UserInfo.UserSetting(userid, OperateType, type, Reason, datetime, CurrentUserInfo.UserName, new Guid(depid), depname, Position, Level);
                }
                else
                {
                    context.Response.Write(retExecResult(Constants.ExecResult.Error, "变动日期小于开始日期，请重新选择变动日期！", ""));
                    return;
                }
            }
            if(setting=="n")
                context.Response.Write(retExecResult(Constants.ExecResult.Succ, "变动成功！", ""));
            else
                context.Response.Write(retExecResult(Constants.ExecResult.Succ, "变动成功！\n此人为高级管理者，请进行职权设置！！如不设，会影响后期人效计算，请注意！", ""));
            //添加操作日志
            //string strSql = string.Format("insert into Hr_UserLogs values(newid(),'{0}','{1}','{2}','{3}','{4}','人事变动','{2}-人事变动:{1}',getdate())", userid, CurrentUserInfo.UserId.ToString(), CurrentUserInfo.UserName, CurrentUserInfo.DepartId.ToString(), CurrentUserInfo.DepartName);
            //Chenxin.Lib.Passport.DAL.Hr_UserInfo.ExecuteSQL(strSql);

            //添加操作日志
            AddLog("" + CurrentUserInfo.UserName + "人事变动:员工姓名[" + olduserinfo.UserName + "(" + olduserinfo.UserCode + ")]",
                    OperationType.OperationTypeComboList()["OprType_ChangePersonnel"].ToString());

            Chenxin.Lib.Passport.Entity.Hr_UserInfo userinfo = Chenxin.Lib.Passport.DAL.Hr_UserInfo.GetEntityById(userid);
            if (OperateType != 1)
                addUserInfo_bak(userinfo, olduserinfo);

            if (OperateType == 3 || OperateType == 5 ||OperateType==1)
            {
                string strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, olduserinfo.DepartId + ".0");
                cs.Delete(strKDepUsers);
                strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, olduserinfo.DepartId + ".1");
                cs.Delete(strKDepUsers);
                strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, olduserinfo.DepartId + ".-1");
                cs.Delete(strKDepUsers);
                strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, userinfo.DepartId + ".0");
                cs.Delete(strKDepUsers);
                strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, userinfo.DepartId + ".1");
                cs.Delete(strKDepUsers);
                strKDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, userinfo.DepartId + ".-1");
                cs.Delete(strKDepUsers);
            }
            else if (OperateType == 2)
            {
                string strKeyDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, userinfo.DepartId + ".-1");
                cs.Delete(strKeyDepUsers);
                strKeyDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, userinfo.DepartId + ".1");
                cs.Delete(strKeyDepUsers);
                strKeyDepUsers = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_DEPARTMENT_USERS, userinfo.DepartId + ".0");
                cs.Delete(strKeyDepUsers);
            }
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }

    //*******************************************
    //功能概要       ：获得人事档案分页数据
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：获得人事档案分页数据
    //作成者         ：薛彦 
    //作成日         ：2010-03-31
    //*******************************************
    private void pageShow(HttpContext context)
    {
        string strwhere = "";
        string stype="";
        DataSet ds = new DataSet();

        Constants.Pagination stuPg = new Constants.Pagination();
        
        //页码
        int pageindex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;//页码
        //页显示行数
        int PageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 30 : int.Parse(context.Request["pagesize"]);//页记录数
        
        string userid = "";
        if (!string.IsNullOrEmpty(context.Request.QueryString["UserId"]))
        {
            userid = context.Request.QueryString["UserId"];
        }
        
        stype=context.Request.QueryString["stype"];
        System.Text.StringBuilder str = new System.Text.StringBuilder();

        if (stype == "terms")
        {strwhere = string.Format("UserId='{0}'", userid);

        ds = Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.GetList(pageindex, PageSize, "Hr_Struct_UserDepartRelation.AddTime desc", "Hr_Struct_UserDepartRelation", strwhere, "RecordId,DepartName,IsBelong,RoleType,ComeDate", "RecordId,DepartName,case IsBelong when 'True' then '√' end as IsBelong,case RoleType when '1' then '业务员'  when '2' then '秘书'  when '3' then '店长'  when '4' then '高经'  when '5' then '区经'  when '6' then '商经' else '总部人员' end as RoleType,Convert(varchar(10),ComeDate,120) as ComeDate", true);
            string td = "";

            str.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew\" id=\"report\">");
            str.Append("<thead><tr>");
            str.Append("<th width=\"50\">部门</th>");
            str.Append("<th width=\"50\">隶属</th>");
            str.Append("<th width=\"50\">职权</th>");
            str.Append("<th width=\"50\">开始时间</th>");
            str.Append("<th width=\"50\">操作</th>");
            str.Append("</tr></thead>");
            str.Append("<tbody>");
            
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string click_str = "";
                if (ds.Tables[0].Rows[i][2].ToString().Trim() == "√")
                    click_str = "name=\"0\"";
                else
                    click_str = string.Format("name=\"{0}\"", ds.Tables[0].Rows[i][0]);

                td = String.Format("<tr id=\"{0}\" ><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td><a class=\"btndel_Terms\" href='#' {5} >删除</a></td></tr>", ds.Tables[0].Rows[i]["RecordId"], ds.Tables[0].Rows[i]["DepartName"], ds.Tables[0].Rows[i]["IsBelong"], ds.Tables[0].Rows[i]["RoleType"], ds.Tables[0].Rows[i]["ComeDate"], click_str);
                str.Append(td);
            }

            str.Append("</tbody></table>");
            
        }
        else if (stype == "pt")
        {
            if (!string.IsNullOrEmpty(context.Request.Params["PostName"]))
                strwhere += string.Format("PostName='{0}' and ", context.Request.Params["PostName"]);
            if (!string.IsNullOrEmpty(context.Request.Params["CompanyID"]))
                strwhere += string.Format("HR_Rel_Office.CompanyID='{0}' and ", context.Request.Params["CompanyID"]);

            strwhere += string.Format("HR_Rel_Office.CompanyID = Hr_DepartmentInfo.DepartId");

            ds = Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.GetList(pageindex, PageSize, "HR_Rel_Office.AddTime desc", "HR_Rel_Office,Hr_DepartmentInfo", strwhere, "RecodID,PostName,OfficeName,DepartName", "RecodID,PostName,OfficeName,DepartName", true);

            str.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew\" id=\"report\">");
            str.Append("<thead><tr>");
            str.Append("<th width=\"50\">职权</th>");
            str.Append("<th width=\"50\">职务</th>");
            str.Append("<th width=\"50\">公司</th>");
            str.Append("<th width=\"50\">操作</th>");
            str.Append("</tr></thead>");
            str.Append("<tbody>");
            
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string td = "";
                td = String.Format("<tr id=\"{3}\" ><td>{0}</td><td>{1}</td><td>{2}</td><td><a id=\"btndel_PosTerms\" href='#' name=\"{3}\" >删除</a></td></tr>", ds.Tables[0].Rows[i]["PostName"], ds.Tables[0].Rows[i]["OfficeName"], ds.Tables[0].Rows[i]["DepartName"], ds.Tables[0].Rows[i]["RecodID"]);
                str.Append(td);
            }
            
            str.Append("</tbody></table>");
            
        }
        int count = (int)ds.Tables[1].Rows[0][0];
        stuPg.count = count;
        stuPg.data = str.ToString();
        //context.Response.Write(str.ToString());         
        context.Response.Write(retExecResult(Constants.ExecResult.Succ, "OK", stuPg));   
        
    }   
        
    //*******************************************
    //功能概要       ：得到所有角色
    //参数説明       ：context 请求的上下文
    //返回值説明     ：角色列表所需的json数据
    //功能詳細       ：得到所有角色
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-04 
    //*******************************************
    //private string getAllRoles()
    //{
    //    //业务角色类
    //    Chenxin.Lib.Hr.BLL.Base_Permit_RoleDefine bllBasePermitRoleDefine = new Chenxin.Lib.Hr.BLL.Base_Permit_RoleDefine();
        
    //    //json数据
    //    string strJson = "{ txt: '请选择', val: '请选择' }";
        
    //    //权限类
    //    List<Chenxin.Lib.Hr.Entity.Base_Permit_RoleDefine> lsRoles = bllBasePermitRoleDefine.GetAllList();
            
    //    //循环列表
    //    for (int idxCnt = 0; idxCnt < lsRoles.Count; idxCnt++)
    //    {
    //        strJson = strJson + ",{ txt: '";
    //        strJson = strJson + lsRoles[idxCnt].RoleName;
    //        strJson = strJson + "', val: '";
    //        strJson = strJson + lsRoles[idxCnt].RoleId.ToString();
    //        strJson = strJson + "' }";
    //    }

    //    return strJson;
    //}

    ////*******************************************
    ////功能概要       ：得到部门
    ////参数説明       ：context 请求的上下文
    ////返回值説明     ：部门列表所需的json数据
    ////功能詳細       ：得到部门
    ////作成者         ：he.jifeng 
    ////作成日         ：2010-03-08 
    ////*******************************************
    //private string getAllDeparts()
    //{
    //    //业务角色类
    //    Chenxin.Lib.Hr.BLL.Hr_DepartmentInfo bllHrDepartmentInfo = new Chenxin.Lib.Hr.BLL.Hr_DepartmentInfo();
        
    //    //json数据
    //    string strJson = "{ txt: '请选择', val: '请选择' }";

    //    //权限类
    //    List<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo> lsDeparts = bllHrDepartmentInfo.GetAllDeparts();

    //    //循环列表
    //    for (int idxCnt = 0; idxCnt < lsDeparts.Count; idxCnt++)
    //    {
    //        strJson = strJson + ",{ txt: '";
    //        strJson = strJson + lsDeparts[idxCnt].DepartName;
    //        strJson = strJson + "', val: '";
    //        strJson = strJson + lsDeparts[idxCnt].DepartId.ToString();
    //        strJson = strJson + "' }";
    //    }

    //    return strJson;
    //}

    //private string getAllCitys()
    //{
    //    //业务角色类
    //    Chenxin.Lib.Hr.BLL.Struct_CityBaseInfo bllCityBaseInfo = new Chenxin.Lib.Hr.BLL.Struct_CityBaseInfo();

    //    //json数据
    //    string strJson = "{ txt: '请选择', val: '请选择' }";
        
    //    List<Chenxin.Lib.Hr.Entity.Struct_CityBaseInfo> lsCitys = bllCityBaseInfo.GetModelList("");
    //    //循环列表
    //    for (int idxCnt = 0; idxCnt < lsCitys.Count; idxCnt++)
    //    {
    //        strJson = strJson + ",{ txt: '";
    //        strJson = strJson + lsCitys[idxCnt].CityName;
    //        strJson = strJson + "', val: '";
    //        strJson = strJson + lsCitys[idxCnt].CityId.ToString();
    //        strJson = strJson + "' }";
    //    }

    //    return strJson;
    //}

    //private string getAllPosition()
    //{
    //    //业务角色类
    //    Chenxin.Lib.House.BLL.DataDictionary bllDic = new Chenxin.Lib.House.BLL.DataDictionary();

    //    //json数据
    //    string strJson = "{ txt: '请选择', val: '请选择' }";

    //    List<Chenxin.Lib.House.Entity.DataDictionary> lsPosition = bllDic.GetDicList("System.Position", CurrentUserInfo.CityId);
    //    //循环列表
    //    for (int idxCnt = 0; idxCnt < lsPosition.Count; idxCnt++)
    //    {
    //        strJson = strJson + ",{ txt: '";
    //        strJson = strJson + lsPosition[idxCnt].ItemValue;
    //        strJson = strJson + "', val: '";
    //        strJson = strJson + lsPosition[idxCnt].ItemValue;
    //        strJson = strJson + "' }";
    //    }

    //    return strJson;
    //}

    //private string getAllEmpLevel()
    //{
    //    //业务角色类
    //    Chenxin.Lib.House.BLL.DataDictionary bllDic = new Chenxin.Lib.House.BLL.DataDictionary();

    //    //json数据
    //    string strJson = "{ txt: '请选择', val: '请选择' }";

    //    List<Chenxin.Lib.House.Entity.DataDictionary> lsPosition = bllDic.GetDicList("System.EmpLevel", CurrentUserInfo.CityId);
    //    //循环列表
    //    for (int idxCnt = 0; idxCnt < lsPosition.Count; idxCnt++)
    //    {
    //        strJson = strJson + ",{ txt: '";
    //        strJson = strJson + lsPosition[idxCnt].ItemValue;
    //        strJson = strJson + "', val: '";
    //        strJson = strJson + lsPosition[idxCnt].ItemValue;
    //        strJson = strJson + "' }";
    //    }

    //    return strJson;
    //}

    ///// <summary>
    ///// 获取公司，通过城市ID
    ///// </summary>
    ///// <param name="cityId">公司所在城市ID，为null是，返回所有公司</param>
    ///// <returns></returns>
    //private string GetCompanyByCity(string cityId)
    //{
    //    string where=" 1=1 and DepartProperty=200";
    //    Chenxin.Lib.Hr.BLL.Hr_DepartmentInfo bll = new Chenxin.Lib.Hr.BLL.Hr_DepartmentInfo();
    //    if (cityId != null)
    //    {
    //        where += " and CityID='" + cityId + "'";
    //    }
    //    DataTable dt = bll.GetList(where).Tables[0];

    //    StringBuilder jsonSb = new StringBuilder();
    //    jsonSb.Append("{ txt: '请选择', val: '0' }");
        
    //    foreach (DataRow dr in dt.Rows)
    //    {
    //        jsonSb.Append(",{");
    //        jsonSb.Append("txt:'" + dr["DepartName"].ToString() + "',val:'" + dr["DepartId"].ToString() + "'");
    //        jsonSb.Append("}");
    //    }
    //    return jsonSb.ToString();
    //}
    
    //*******************************************
    //功能概要       ：得到人员信息
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：得到人员信息
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-04 
    //*******************************************
    private void searchUserInfo(HttpContext context, string showtype)
    {
        //参数列表
        System.Collections.Hashtable htParams = new System.Collections.Hashtable();
        //当前参数
        string strParam;

        //条件
        strParam = context.Request.Params["Condition"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("Condition", strParam);
        }
        //生日
        strParam = context.Request.Params["divBirthday"];
        if (strParam != null & strParam != ""&strParam!="0")
        {
            htParams.Add("divBirthday", strParam);
        }
        //状态
        strParam = context.Request.Params["divStatus"];
        //全部或者为空的场合
        if (strParam != null & strParam != "" & strParam != "0")
        {
            htParams.Add("Status", strParam);
        }
        //到职时间（开始）
        strParam = context.Request.Params["ComeDateFrom"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("ComeDateFrom", strParam);
        }
        //到职时间（结束）
        strParam = context.Request.Params["ComeDateTo"];
        if (strParam != null & strParam != null & strParam != "")
        {
            htParams.Add("ComeDateTo", strParam);
        }
        //合同开始时间（开始）
        strParam = context.Request.Params["ContractDateFrom"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("ContractDateFrom", strParam);
        }
        //合同开始时间（结束）
        strParam = context.Request.Params["ContractDateTo"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("ContractDateTo", strParam);
        }
        //离职时间（开始）
        strParam = context.Request.Params["LeaveDateFrom"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("LeaveDateFrom", strParam);
        }
        //离职时间（结束）
        strParam = context.Request.Params["LeaveDateTo"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("LeaveDateTo", strParam);
        }
        //身份证号
        strParam = context.Request.Params["IDNo"];
        if (strParam != null & strParam != "")
        {
            htParams.Add("IDNo", strParam);
        }
        //角色
        strParam = context.Request.Params["divRole"];
        if (strParam != null & strParam != "" & strParam != "0")
        {
            htParams.Add("RoleId", strParam);
        }
        //职务
        strParam = context.Request.Params["Position"];
        if (strParam != null & strParam != "" & strParam != "0")
        {
            htParams.Add("Position", strParam);
        }
        //虚账号
        strParam = context.Request.Params["divIsVirtual"];
        if (strParam != null)
        {
            htParams.Add("IsVirtual", strParam);
        }
        //公积金账号
        strParam = context.Request.Params["FundCode"];
        if (strParam != null)
        {
            htParams.Add("FundCode", strParam);
        }
        //手机号码
        strParam = context.Request.Params["Mobile"];
        if (strParam != null)
        {
            htParams.Add("Mobile", strParam);
        }
        //家庭电话
        strParam = context.Request.Params["HomeTel"];
        if (strParam != null)
        {
            htParams.Add("HomeTel", strParam);
        }
        //办公电话
        strParam = context.Request.Params["OfficeTel"];
        if (strParam != null)
        {
            htParams.Add("OfficeTel", strParam);
        }
        //快捷方式
        strParam = context.Request.Params["quicktype"];
        if (strParam != null)
        {
            htParams.Add("quicktype", strParam);
        }
        //排序
        strParam = context.Request.Params["sort"];
        if (!string.IsNullOrEmpty(strParam))
        {
            htParams.Add("sort", strParam);
        }
        

        //当前页数
        strParam = (string.IsNullOrEmpty(context.Request["pageindex"])) ? "1" : (int.Parse(context.Request["pageindex"]) + 1).ToString();
        htParams.Add("page", strParam);
        //显示行数
        strParam = (string.IsNullOrEmpty(context.Request["pagesize"])) ? "30" : context.Request["pagesize"];//页记录数
        htParams.Add("rows", strParam);


        strParam = context.Request.Params["keyword"];
        if (!string.IsNullOrEmpty(strParam))
        {
            htParams.Add("keyword", strParam);
        }

        strParam = showtype;
        htParams.Add("show", strParam);

        strParam = (string.IsNullOrEmpty(context.Request["cityid"])) ? Guid.Empty.ToString() : context.Request["cityid"];
        htParams.Add("cityid_s", strParam);
        strParam = (string.IsNullOrEmpty(context.Request["companyid"])) ? Guid.Empty.ToString() : context.Request["companyid"];
        if (context.Request["cityid"] == Guid.Empty.ToString() ||string.IsNullOrEmpty(context.Request["cityid"]))
            htParams.Add("companyid_s", CurrentUserInfo.CompanyId.ToString());
        else
            htParams.Add("companyid_s", strParam);
        strParam = (string.IsNullOrEmpty(context.Request["areaid"])) ? Guid.Empty.ToString() : context.Request["areaId"];
        htParams.Add("areaid_s", strParam);
        strParam = (string.IsNullOrEmpty(context.Request["departid"])) ? Guid.Empty.ToString() : context.Request["departid"];
        htParams.Add("departid_s", strParam);
        strParam = (string.IsNullOrEmpty(context.Request["userid"])) ? Guid.Empty.ToString() : context.Request["userid"];
        htParams.Add("userid_s", strParam);

        //权限判断
        //查看所有权限
        if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewAllHrUserInfo))
        {
            htParams.Add("Permit", Constants.Permit_ViewAllHrUserInfo);
        }
        //查看城市权限
        else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewCityHrUserInfo))
        {
            htParams.Add("Permit", Constants.Permit_ViewCityHrUserInfo);
            htParams.Add("CurCityId", CurrentUserInfo.CityId);
        }
        //查看公司权限
        else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewCompanyHrUserInfo))
        {
            htParams.Add("Permit", Constants.Permit_ViewCompanyHrUserInfo);
            htParams.Add("CurCompanyId", CurrentUserInfo.CompanyId);
        }
        //查看部门权限
        else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewDepartHrUserInfo))
        {
            htParams.Add("Permit", Constants.Permit_ViewDepartHrUserInfo);
            htParams.Add("CurUserId", CurrentUserInfo.UserId);
        }
        //查看自己权限    
        else
        {
            htParams.Add("CurUserId", CurrentUserInfo.UserId);
        }
                
        try
        {
            Chenxin.Lib.Passport.BLL.Hr_UserInfo blluserinfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();
            int count = 0;
            string strHtml = blluserinfo.GetModelListByCoditions(htParams, out count);
            string strhead = blluserinfo.GetHead(showtype);
            
            
            context.Response.Write(string.Format("{{success:'1',msg:'{0}',data:{{count:'{1}',html:'{2}',head:{3}}}}}", "成功", count, strHtml, strhead));
        }
        catch (Exception ex)
        {
            context.Response.Write(string.Format("{{success:'0',msg:'意外错误：{0}',data:''}}", ex.Message));            
        }
        
    }
    

    //*******************************************
    //功能概要       ：匹配条件
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：匹配条件
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-09 
    //*******************************************
    public void getCondition(HttpContext context)
    {
        StringBuilder strHtml = new StringBuilder();

        string strQuery = context.Request.QueryString["query"];

        try
        {

            Chenxin.Lib.Passport.BLL.Hr_UserInfo bllUserInfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();

            System.Collections.ArrayList lsUsersDeparts = bllUserInfo.GetUsersDeparts(strQuery);

            List<Chenxin.Lib.Passport.Entity.Hr_UserInfo> lsUserInfo = (List<Chenxin.Lib.Passport.Entity.Hr_UserInfo>)lsUsersDeparts[0];
            List<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo> lsDepartInfo = (List<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo>)lsUsersDeparts[1];

            
            if (lsUserInfo.Count > 0)
            {
                strHtml.Append("<dt>人员</dt>");
                
                //strHtml.Append("<div>");
                //strHtml.Append("<label>人员</label>");
                //strHtml.Append("<br />");
                //strHtml.Append("<ul class='clsMatch'>");
                int usercount = 0;
                foreach (Chenxin.Lib.Passport.Entity.Hr_UserInfo lsUser in lsUserInfo)
                {
                    //strHtml.Append("<li>");
                    //strHtml.Append("<div class='clsUserInfo'>");
                    string strShowNm = lsUser.UserName + "(" + lsUser.UserCode+ ")";
                    strHtml.Append("<dd>");
                    strHtml.Append(" <input type=hidden name='hidType' value='UserInfo' />");
                    strHtml.Append(" <input type=hidden name='hidId' value='" + lsUser.UserId.ToString() + "' />");
                    strHtml.Append(" <input type=hidden name='hidNm' value='" + strShowNm + "' />");
                    strHtml.Append(" <a class='clsAUser' href='#'>" + strShowNm + "</a>");
                    strHtml.Append("</dd>");
                    //strHtml.Append("</div>");
                    //strHtml.Append("</li>");
                    usercount++;
                    if (usercount > 20)
                        break;
                }
                //strHtml.Append("</ul>");
                //strHtml.Append("</div>");
            }


            if (lsDepartInfo.Count > 0)
            {
                strHtml.Append("<dt>部门</dt>");
                //strHtml.Append("<div>");
                //strHtml.Append("<label>部门</label>");
                //strHtml.Append("<br />");
                //strHtml.Append("<ul class='clsMatch'>");
                int depcount = 0;
                foreach (Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo lsDepart in lsDepartInfo)
                {
                    //strHtml.Append("<li>");
                    //strHtml.Append("<div class='clsUserInfo'>");
                    strHtml.Append("<dd>");
                    strHtml.Append(" <input type=hidden name='hidType' value='DepartInfo' />");
                    strHtml.Append(" <input type=hidden name='hidId' value='" + lsDepart.DepartId.ToString() + "' />");
                    strHtml.Append(" <input type=hidden name='hidNm' value='" + lsDepart.DepartName + "("+lsDepart.CompanyName+")' />");
                    strHtml.Append(" <a id='clsAUser' href='#'>" + lsDepart.DepartName + "</a>");
                    strHtml.Append("</dd>");
                    //strHtml.Append("</div>");
                    //strHtml.Append("</li>");
                    depcount++;
                    if (depcount > 20)
                        break;
                }
                //strHtml.Append("</ul>");
                //strHtml.Append("</div>");
            }
            
       
          //响应内容
            context.Response.Write(JsonHelper<string>.WriteObject("SUCCESS", strHtml.ToString()));
        }
        catch(Exception ex)
        {
            //错误信息回传
            context.Response.Write(JsonHelper<string>.WriteObject("ERROR", ex.Message));
        }
    }
    
    //*******************************************
    //功能概要       ：用户基本信息数据登录
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：用户基本信息数据登录
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-07 
    //*******************************************
    public void addUserInfo(HttpContext context)
    {
        
        try
        {
            //用户基本信息业务类
            Chenxin.Lib.Passport.BLL.Hr_UserInfo bllUserInfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();
            //用户基本信息实体类
            Chenxin.Lib.Passport.Entity.Hr_UserInfo entUserInfo =
            (Chenxin.Lib.Passport.Entity.Hr_UserInfo)Chenxin.Lib.Utility.JsonHelp.Convert2Entity(context.Request["model"], typeof(Chenxin.Lib.Passport.Entity.Hr_UserInfo));

            //用户Id
            entUserInfo.UserId = Guid.NewGuid();
            //用户类型
            entUserInfo.UserType = 0;
            //操作人员
            entUserInfo.AddPerson = CurrentUserInfo.UserName;
            //操作部门
            entUserInfo.AddDepart = CurrentUserInfo.DepartName;
            //状态
            entUserInfo.Status = 1;
            //密码（暂时固定）
            entUserInfo.Password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("123456", "MD5");
            //姓名品应首字母
            entUserInfo.Initial = Chenxin.Lib.Utility.InitialHelper.GetChineseSpell(entUserInfo.UserName).Substring(0, 1);
            //是否虚拟账号
            entUserInfo.IsVirtual = false;
            //员工编号
            string companyCode = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetModel(entUserInfo.CompanyId).DepartCode;
            string usercode = Chenxin.Lib.Passport.BLL.Hr_UserInfo.GetUserCode(entUserInfo.CompanyId, companyCode);
            entUserInfo.UserCode = usercode;
            //流水号
            entUserInfo.SerialCode = entUserInfo.UserCode.Replace(companyCode, "");
            //是否冻结
            entUserInfo.Validate = false;

            string flag = bllUserInfo.Add(entUserInfo);
            if(flag!="y")
                context.Response.Write(retExecResult(Constants.ExecResult.Succ, "", "注册成功!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;员工编号:" + usercode + ""));
            else
                context.Response.Write(retExecResult(Constants.ExecResult.Succ, "", "注册成功!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;员工编号:" + usercode + "<br>此人为高级管理者，请进行职权设置！！如不设，会影响后期人效计算，请注意！"));

            string rolelist = context.Request.Params["role"];
            if (!string.IsNullOrEmpty(rolelist) && rolelist != "undefined")
            {
                string strSql = "";
                string[] array = rolelist.Split(',');
                foreach (string s in array)
                {
                    strSql += string.Format("insert into Base_RoleUserRelationInfo values(newid(),'{0}','{1}');", s, entUserInfo.UserId);
                }
                Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.ExecuteSQL(strSql);
            }
            //添加操作日志
            AddLog("" + CurrentUserInfo.UserName + "添加员工:员工姓名[" + entUserInfo.UserName + "(" + entUserInfo.UserCode + ")]",
                    OperationType.OperationTypeComboList()["OprType_UserAdd"].ToString()); 
            
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }
    
    //*******************************************
    //功能概要       ：删除用户基本信息数据
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：删除用户基本信息数据
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-07 
    //*******************************************
    //public void delUserInfo(HttpContext context)
    //{
    //    //用户Id
    //    string strUserId = context.Request.Params["UserId"];
    //    //用户业务类
    //    Chenxin.Lib.Passport.BLL.Hr_UserInfo bllHrUserInfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();

    //    try
    //    {
    //        //用户删除
    //        bllHrUserInfo.Delete(new Guid(strUserId));
    //        context.Response.Write(JsonHelper<string>.WriteObject("SUCCESS", ""));
    //    }
    //    catch (Exception ex)
    //    {
    //        context.Response.Write(JsonHelper<string>.WriteObject("ERROR", ex.Message));
    //    }
    //}

    //*******************************************
    //功能概要       ：得到用户基本信息数据
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：得到用户基本信息数据
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-07 
    //*******************************************
    public void getUserInfo(HttpContext context)
    {
        try
        {
            string strUserId = context.Request.Params["UserId"];
            //业务类
            Chenxin.Lib.Passport.BLL.Hr_UserInfo bllHrUserInfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();
            //实体类
            Chenxin.Lib.Passport.Entity.Hr_UserInfo entHrUserInfo = bllHrUserInfo.GetEntityById(new Guid(strUserId));

            //响应内容
            context.Response.Write(retExecResult(Constants.ExecResult.Succ, "OK", entHrUserInfo));
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }

    //*******************************************
    //功能概要       ：编辑用户基本信息数据
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：编辑用户基本信息数据
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-07 
    //*******************************************
    public void editUserInfo(HttpContext context)
    {

        try
        {
            //用户基本信息业务类
            Chenxin.Lib.Passport.BLL.Hr_UserInfo bllUserInfo = new Chenxin.Lib.Passport.BLL.Hr_UserInfo();
            //用户基本信息实体类
            Chenxin.Lib.Passport.Entity.Hr_UserInfo entUserInfo =
            (Chenxin.Lib.Passport.Entity.Hr_UserInfo)Chenxin.Lib.Utility.JsonHelp.Convert2Entity(context.Request["model"], typeof(Chenxin.Lib.Passport.Entity.Hr_UserInfo));

            Chenxin.Lib.Passport.Entity.Hr_UserInfo entHrUserInfo = bllUserInfo.GetEntityById(entUserInfo.UserId);

            string change = bllUserInfo.CheckChange(entHrUserInfo, entUserInfo);

            addUserInfo_bak(entUserInfo, entHrUserInfo);
            
            string strSql = "";
            if(entHrUserInfo.BelongDepartId!=entUserInfo.BelongDepartId)
                strSql = string.Format("update Struct_UserDepartRelation set DepartId='{0}',DepartName='{1}' where UserId='{2}' and IsBelong='True';", entUserInfo.BelongDepartId.ToString(), entUserInfo.BelongDepart, entUserInfo.UserId.ToString());
            
            //用户姓名
            entHrUserInfo.UserName = entUserInfo.UserName;
            //性别
            entHrUserInfo.Sex = entUserInfo.Sex;
            //是否冻结
            entHrUserInfo.Status = entUserInfo.Status;
            //证件类型
            entHrUserInfo.IDType = entUserInfo.IDType;
            //证件号码
            entHrUserInfo.IDNo = entUserInfo.IDNo;
            //手机号
            entHrUserInfo.Mobile = entUserInfo.Mobile;
            //家庭电弧
            entHrUserInfo.HomeTel = entUserInfo.HomeTel;
            //地址
            entHrUserInfo.Address = entUserInfo.Address;
            //生日
            entHrUserInfo.BirthDay = entUserInfo.BirthDay;
            //教育程度
            entHrUserInfo.Education = entUserInfo.Education;
            //工作电话
            entHrUserInfo.OfficeTel = entUserInfo.OfficeTel;
            //银行帐号
            entHrUserInfo.BankNo = entUserInfo.BankNo;
            //公积金帐号
            entHrUserInfo.FundCode = entUserInfo.FundCode;
            //备注
            entHrUserInfo.Remark = entUserInfo.Remark;
            //合同开始
            entHrUserInfo.ConBegin = entUserInfo.ConBegin;
            //合同结束
            entHrUserInfo.ConEnd = entUserInfo.ConEnd;
            //工龄起始日
            entHrUserInfo.WorkAgeBegin = entUserInfo.WorkAgeBegin;
            //所属及业务城市id
            entHrUserInfo.CityId = entHrUserInfo.BelongCityId = entUserInfo.BelongCityId;
            //所属及业务城市名称
            entHrUserInfo.CityName = entHrUserInfo.BelongCityName = entUserInfo.BelongCityName;
            //所属及业务公司id
            entHrUserInfo.CompanyId = entHrUserInfo.BelongCompanyId = entUserInfo.BelongCompanyId;
            //所属及业务公司名称
            entHrUserInfo.CompanyName = entHrUserInfo.BelongCompanyName = entUserInfo.BelongCompanyName;
            //所属及业务部门ID
            entHrUserInfo.BelongDepartId = entHrUserInfo.DepartId = entUserInfo.BelongDepartId;
            //所属及业务部门名称
            entHrUserInfo.DepartName = entHrUserInfo.BelongDepart = entUserInfo.BelongDepart;
            //入职时间
            entHrUserInfo.ComeDate = entUserInfo.ComeDate;
            //职务
            entHrUserInfo.Position = entUserInfo.Position;
            //职级
            entHrUserInfo.EmpLevel = entUserInfo.EmpLevel;
            //邮编
            entHrUserInfo.Zip = entUserInfo.Zip;
            //劳动关系
            entHrUserInfo.WorkRelation = entUserInfo.WorkRelation;
            
            
            entHrUserInfo.UpdateTime = DateTime.Now;

            //if (entHrUserInfo.Status == 1)
            //    entHrUserInfo.LeaveDate = null;
            
            //更新数据
            bllUserInfo.Update(entHrUserInfo);
                
            //更新业务设定
            if (strSql.Length > 0)
                Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.ExecuteSQL(strSql);

            
            //添加操作日志
            AddLog("" + CurrentUserInfo.UserName + "编辑员工:员工姓名[" + entHrUserInfo.UserName + "(" + entHrUserInfo.UserCode + ")]。"+change,
                    OperationType.OperationTypeComboList()["OprType_UserEdit"].ToString());          

            context.Response.Write(retExecResult(Constants.ExecResult.Succ, "修改成功", ""));
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }

    //*******************************************
    //功能概要       ：得到用户调动数据
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：得到用户调动数据
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-08 
    //*******************************************
    public void getTransferInfo(HttpContext context)
    {
        string strUserId = context.Request.Params["UserId"];
    }

    //*******************************************
    //功能概要       ：添加更该的字段信息
    //参数説明       ：
    //返回值説明     ：
    //功能詳細       ：添加更该的字段信息
    //作成者         ：chenyg
    //作成日         ：2010-03-01
    //修改者         ：
    //修改日         ：
    //*******************************************
    private void adduserInfo_BakCol(string colomuName, string colomuDesc, string oldValue, string newValue,Guid userid)
    {
        Chenxin.Lib.Hr.Entity.Hr_UserInfo_BakCol userInfo_BakCol = new Chenxin.Lib.Hr.Entity.Hr_UserInfo_BakCol();
        string changeDesc = colomuDesc + "由:" + oldValue + " 修改为:" + newValue + " ";

        userInfo_BakCol.RecordId = Guid.NewGuid();
        userInfo_BakCol.ColumnName = colomuName;
        userInfo_BakCol.ColumnDesc = colomuDesc;
        userInfo_BakCol.OldValue = oldValue;
        userInfo_BakCol.NewValue = newValue;
        userInfo_BakCol.ChangeDesc = changeDesc;
        userInfo_BakCol.UserId = userid;

        userInfo_BakCol.OperatorId = CurrentUserInfo.UserId;
        userInfo_BakCol.Operator = CurrentUserInfo.UserName;
        userInfo_BakCol.DepartId = CurrentUserInfo.DepartId;
        userInfo_BakCol.Depart = CurrentUserInfo.DepartName;
        userInfo_BakCol.CompanyId = CurrentUserInfo.CompanyId;
        userInfo_BakCol.CompanyName = CurrentUserInfo.CompanyName;
        userInfo_BakCol.CityId = CurrentUserInfo.CompanyId;
        userInfo_BakCol.CityName = CurrentUserInfo.CompanyName;
        
        userInfo_BakCol.Adddate = DateTime.Now;
        Chenxin.Lib.Hr.DAL.Hr_UserInfo_BakCol.Add(userInfo_BakCol);
    }
    //*******************************************
    //功能概要       ：写入房源更改记录
    //参数説明       ：
    //返回值説明     ：
    //功能詳細       ：写入房源更改记录
    //作成者         ：chenyg
    //作成日         ：2010-03-01
    //修改者         ：
    //修改日         ：
    //*******************************************
    private void addUserInfo_bak(Chenxin.Lib.Passport.Entity.Hr_UserInfo userinfo, Chenxin.Lib.Passport.Entity.Hr_UserInfo olduserinfo)
    {
        StringBuilder updateContext = new StringBuilder();

        //城市
        if (!strEqual(userinfo.BelongCityId.ToString(), olduserinfo.BelongCityId.ToString()))
        {
            adduserInfo_BakCol("BelongCityName", "隶属城市", olduserinfo.BelongCityName, userinfo.BelongCityName,userinfo.UserId);
        }
        //公司
        if (!strEqual(userinfo.BelongCompanyId.ToString(), olduserinfo.BelongCompanyId.ToString()))
        {
            adduserInfo_BakCol("BelongCompanyName", "隶属公司", olduserinfo.BelongCompanyName, userinfo.BelongCompanyName, userinfo.UserId);
        }
        //部门
        if (!strEqual(userinfo.BelongDepartId.ToString(), olduserinfo.BelongDepartId.ToString()))
        {
            adduserInfo_BakCol("BelongDepart", "隶属部门", olduserinfo.BelongDepart, userinfo.BelongDepart, userinfo.UserId);
        }
        //职级
        if (!strEqual(userinfo.EmpLevel, olduserinfo.EmpLevel))
        {
            adduserInfo_BakCol("EmpLevel", "职级", olduserinfo.EmpLevel, userinfo.EmpLevel, userinfo.UserId);
        }
        //职务
        if (!strEqual(userinfo.Position, olduserinfo.Position))
        {
            adduserInfo_BakCol("Position", "职务", olduserinfo.Position, userinfo.Position, userinfo.UserId);
        }
        //姓名
        if (!strEqual(userinfo.UserName, olduserinfo.UserName))
            adduserInfo_BakCol("UserName", "姓名", olduserinfo.UserName, userinfo.UserName, userinfo.UserId);
        //性别
        if (!strEqual(olduserinfo.Sex.ToString(), userinfo.Sex.ToString()))
            adduserInfo_BakCol("Sex","性别",olduserinfo.Sex.ToString() == "0" ? "男" : "女", userinfo.Sex.ToString() == "0" ? "男" : "女",userinfo.UserId);
        //学历
        if (!strEqual(olduserinfo.Education, userinfo.Education))
            adduserInfo_BakCol("Education", "学历", olduserinfo.Education, userinfo.Education,userinfo.UserId);
        //证件类型
        if (!strEqual(olduserinfo.IDType, userinfo.IDType))
            adduserInfo_BakCol("IDType", "证件类型", olduserinfo.IDType, userinfo.IDType,userinfo.UserId);
        //证件号
        if (!strEqual(olduserinfo.IDNo, userinfo.IDNo))
            adduserInfo_BakCol("IDNo","证件号", olduserinfo.IDNo, userinfo.IDNo,userinfo.UserId);
        //生日
        if (!strEqual(olduserinfo.BirthDay.ToString(), userinfo.BirthDay.ToString()))
            adduserInfo_BakCol("BirthDay","生日", olduserinfo.BirthDay.ToString(), userinfo.BirthDay.ToString(),userinfo.UserId);
        //地址
        if (!strEqual(olduserinfo.Address, userinfo.Address))
            adduserInfo_BakCol("Address","地址", olduserinfo.Address, userinfo.Address,userinfo.UserId);
        //手机
        if (!strEqual(olduserinfo.Mobile, userinfo.Mobile))
            adduserInfo_BakCol("Mobile", "手机", olduserinfo.Mobile, userinfo.Mobile,userinfo.UserId);
        //家庭电话
        if (!strEqual(olduserinfo.HomeTel, userinfo.HomeTel))
            adduserInfo_BakCol("HomeTel","家庭电话", olduserinfo.HomeTel, userinfo.HomeTel,userinfo.UserId);
        //办公电话
        if (!strEqual(olduserinfo.OfficeTel, userinfo.OfficeTel))
            adduserInfo_BakCol("OfficeTel","办公电话", olduserinfo.OfficeTel, userinfo.OfficeTel,userinfo.UserId);
        //工资账号
        if (!strEqual(olduserinfo.BankNo, userinfo.BankNo))
            adduserInfo_BakCol("BankNo", "工资账号", olduserinfo.BankNo, userinfo.BankNo,userinfo.UserId);
        //合同起始日
        if (!strEqual(olduserinfo.ConBegin.ToString(), userinfo.ConBegin.ToString()))
            adduserInfo_BakCol("ConBegin", "合同起始日", olduserinfo.ConBegin.ToString(), userinfo.ConBegin.ToString(),userinfo.UserId);
        //合同终止日
        if (!strEqual(olduserinfo.ConEnd.ToString(), userinfo.ConEnd.ToString()))
            adduserInfo_BakCol("ConEnd", "合同终止日", olduserinfo.ConEnd.ToString(), userinfo.ConEnd.ToString(), userinfo.UserId);
        //公积金账号
        if (!strEqual(olduserinfo.FundCode, userinfo.FundCode))
            adduserInfo_BakCol("FundCode","公积金账号", olduserinfo.FundCode, userinfo.FundCode,userinfo.UserId);
        //备注
        if (!strEqual(olduserinfo.Remark, userinfo.Remark))
            adduserInfo_BakCol("Remark", "备注", olduserinfo.Remark, userinfo.Remark,userinfo.UserId);
        //工龄起始日
        if (!strEqual(olduserinfo.WorkAgeBegin.ToString(), userinfo.WorkAgeBegin.ToString()))
            adduserInfo_BakCol("WorkAgeBegin", "工龄起始日", olduserinfo.WorkAgeBegin.ToString(), userinfo.WorkAgeBegin.ToString(),userinfo.UserId);
       
        //邮箱
        if (!strEqual(olduserinfo.Email, userinfo.Email))
            adduserInfo_BakCol("Email", "邮箱", olduserinfo.Email, userinfo.Email,userinfo.UserId);
        //邮编
        if (!strEqual(olduserinfo.Zip, userinfo.Zip))
            adduserInfo_BakCol("Zip", "邮编", olduserinfo.Zip, userinfo.Zip, userinfo.UserId);
        //在职状态
        if (!strEqual(olduserinfo.Status.ToString(), userinfo.Status.ToString()))
            adduserInfo_BakCol("Status", "在职状态", olduserinfo.Status.ToString(), userinfo.Status.ToString(), userinfo.UserId);
        
        //变动时间
        string strSql=string.Format("userid='{0}' and isbelong=1 order by addtime desc",userinfo.UserId.ToString());
        List<Chenxin.Lib.Hr.Entity.Hr_Struct_UserDepartRelation> list = Chenxin.Lib.Hr.DAL.Hr_Struct_UserDepartRelation_History.GetListArray(strSql);
        if (list.Count > 0)
        {
            Chenxin.Lib.Hr.Entity.Hr_Struct_UserDepartRelation hr = list[0] as Chenxin.Lib.Hr.Entity.Hr_Struct_UserDepartRelation;
            adduserInfo_BakCol("ComeDate", "变动时间", hr.ComeDate.ToString(), hr.LeaveDate.ToString(), userinfo.UserId);
        }
    }

    //*******************************************
    //功能概要       ：比较字符串是否相等
    //参数説明       ：
    //返回值説明     ：
    //功能詳細       ：比较字符串是否相等
    //作成者         ：姚志强
    //作成日         ：2010-03-01
    //修改者         ：
    //修改日         ：
    //*******************************************
    private static bool strEqual(string str1, string str2)
    {
        if (str1 == null)
        {
            str1 = "";
        }

        if (str2 == null)
        {
            str2 = "";
        }

        return str1.Equals(str2);
    }

    
    //*******************************************
    //功能概要       ：响应字符串
    //参数説明       ：strMsg 消息 
    //返回值説明     ：void
    //功能詳細       ：权限检查
    //作成者         ：chen.yugong 
    //作成日         ：2010-05-20
    //修改者         ：
    //修改日         ：
    //*******************************************
    public override bool CustomerCheckPermint(HttpContext context, out string strMsg)
    {
        context.Response.ContentType = "text/plain";
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        
        string op = context.Request.Params["op"];

        if (String.IsNullOrEmpty(op))
        {
            strMsg = "{success:0,msg:'操作参数有误！',data:''}";
            return false;
        }
        op = op.ToLower();

        string code = context.Request.Params["code"];
        if (op.Equals("checkpermit"))
        {
            if (String.IsNullOrEmpty(code))
            {
                strMsg = "{success:0,msg:'权限检查参数有误！',data:''}";
                return false;
            }
            code = code.ToLower();
            //权限判断
            //传递参数用
            System.Collections.Hashtable per = new System.Collections.Hashtable();
            System.Collections.Hashtable confine = new System.Collections.Hashtable();
            
            //编辑客户
            if (code.Equals("edit"))
            {
                if (CurrentUserInfo.ContainsPermit(Constants.Permit_Hr_EditUserKey))
                {
                    strMsg = "{success:1,msg:'',data:{permit:{editall:true}}}";
                    return true;
                }
                else
                {
                    strMsg = "{success:1,msg:'',data:{permit:{editall:false}}}";
                    return true;
                }
            }
        }
        strMsg = "{success:1,msg:'',data:{permit:true}}";
        return true;
    }
}